package neusoft.yuejian_11.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import neusoft.yuejian_11.activity.EventDetailActivity;
import neusoft.yuejian_11.base.BaseListAdapter;
import neusoft.yuejian_11.bean.EventBean;
import neusoft.yuejian_11.R;
import neusoft.yuejian_11.viewHolder.EventitemViewHolder;

import static neusoft.yuejian_11.interF.Const.BASE_URI;

/**
 * Created by neusoft on 2017/10/9.
 */

public class EventListAdapter extends BaseListAdapter {
    public EventListAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_event_list, parent, false);
        EventitemViewHolder viewHolder = new EventitemViewHolder(itemView);
        return viewHolder;
    }

    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, List data, int position) {
        EventBean event = (EventBean) data.get(position);
        EventitemViewHolder viewHolder = (EventitemViewHolder) holder;

        final String activityName = event.getA_name();
        final int activityId = event.getA_id();
        final String activityPhone = event.getA_phone();

        viewHolder.eventNameView.setText(activityName);

        final String activityPicture = BASE_URI+"activitypicture/"+event.getA_picture();
        Picasso.with(context)
                .load(activityPicture)
                .placeholder(R.drawable.ic_club)
                .error(R.drawable.ic_noclub)
                .into(viewHolder.imageView);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //启动新的Activity--俱乐部详情
                Intent intent = new Intent(context, EventDetailActivity.class);
                intent.putExtra("a_name",activityName);
                intent.putExtra("a_id",activityId);
                intent.putExtra("a_picture",activityPicture);
                intent.putExtra("a_phone",activityPhone);
                context.startActivity(intent);
            }
        });

    }
}
